package com.gnerv.battle.boot.project.guard.service.impl;

import com.gnerv.battle.boot.project.guard.mapper.MonitorHostMapper;
import com.gnerv.battle.boot.project.guard.model.bo.MonitorHostBO;
import com.gnerv.battle.boot.project.guard.model.dto.MonitorHostDTO;
import com.gnerv.battle.boot.project.guard.model.entity.MonitorHost;
import com.gnerv.battle.boot.project.guard.service.MonitorHostService;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.gnerv.battle.boot.common.tools.PageTools.limitSize;
import static com.gnerv.battle.boot.common.tools.PageTools.limitStart;

/**
 * @author Gnerv LiGen
 */
@Slf4j
@Service
@AllArgsConstructor
public class MonitorHostServiceImpl implements MonitorHostService {
    
    private final MonitorHostMapper monitorHostMapper;

    @Override
    public boolean create(@NonNull MonitorHostBO monitorHostBO) {
        MonitorHost monitorHost = monitorHostBO.toCreateMonitorHost();
        monitorHostMapper.insert(monitorHost);
        return true;
    }

    @Override
    public boolean deleteByUkId(@NonNull String ukId) {
        monitorHostMapper.deleteByUkId(ukId);
        return true;
    }

    @Override
    public boolean updateByUkId(@NonNull MonitorHostBO monitorHostBO) {
        MonitorHost monitorHost = monitorHostBO.toUpdateMonitorHost();
        monitorHostMapper.updateByUkId(monitorHost);
        return true;
    }

    @Override
    public MonitorHostDTO selectByUkId(@NonNull String ukId) {
        return monitorHostMapper.selectByUkId(ukId);
    }

    @Override
    public List<MonitorHostDTO> listByName(String name, Integer page, Integer size) {
        return monitorHostMapper.listByName(name, limitStart(page, size), limitSize(size));
    }

    @Override
    public MonitorHostDTO selectByNodeUkId(String nodeUkId) {
        return monitorHostMapper.selectByNodeUkId(nodeUkId);
    }


}
